package com.yanqu.road.server.cmd.activity.union;

import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;

@Cmd(code = GameProtocol.S_SYNC_CROSS_UNION_RECHARGE_INFO, desc = "")
public class CrossUnionRechargeSyncInfoCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        CrossUnionActivityRankDataProto.CrossUnionRechargeSyncMsg msg = CrossUnionActivityRankDataProto.CrossUnionRechargeSyncMsg.parseFrom(packet.getBytes());
        int activityId = msg.getActivityId();
        String unionId = msg.getUnionId();
        String info = msg.getInfo();
        Map<Long, CrossUnionMember> unionMemberMap = CrossUnionMgr.getUnionMemberMap(unionId);
        for (UnionMember member : unionMemberMap.values()) {
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(member.getUserId());
            if (player != null) {
                player.getModule(ActivityModule.class).changeUnionRechargeData(activityId, info, 1);

            }
        }
    }
}
